import React from 'react';
import './login.css'
import {login} from '../../redux/login/login'
import { connect } from 'react-redux'
import {withRouter } from 'react-router-dom'
import { Tabs } from 'antd';
import PassWord from './PassWord'
import SMSLogin from './SMSLogin'
const TabPane = Tabs.TabPane;

@withRouter
@connect(
    state => state,
    { login }
)
export default class Login extends React.Component{
    constructor(){
        super();
        this.state = {
            visible : false,
            key:"2"
        }
    }
    componentDidUpdate(){
        if(this.props.userLogin.res == 'true'){
             this.props.history.push('/menuList/1')
        }else{

        }
    }
    callback(key){
     this.setState({
        key:key
     })
    }
    onLogin(){
        let iPhone = document.getElementById('iPhone').value
        let password = document.getElementById('password').value
        this.props.login(iPhone,password)
    }
    fPassword(){
        this.props.history.push('/login/2')
    }
    register(key){
        this.setState({
            key:key
        })
    }
    render() {
        return (
            <div className='login'>
                 <Tabs defaultActiveKey="1" activeKey={this.state.key} onChange={this.callback.bind(this)}>
                    <TabPane tab="密码登录" key="1">
                    <div style={{marginTop:'15px'}}><PassWord register={this.register.bind(this)}/></div>
                    </TabPane>
                    <TabPane tab="短信登录" key="2">
                    <div style={{marginTop:'15px'}}><SMSLogin/></div>
                    </TabPane>
                </Tabs>
            </div>
        )
    }
}